package Thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2023-02-07
 * Time: 22:23
 */

public class Thread15 {
    public static void main(String[] args) {
        Object lock1 = new Object();
        Object  lock2= new Object();
        Thread t1 = new Thread(()->{
            synchronized (lock1){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                     e.printStackTrace();
                }
                synchronized (lock2){
                    System.out.println("t1把锁1和锁2都获得了");
                }
            }

        });
         Thread t2 = new Thread(()->{
            synchronized (lock1){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (lock2){
                    System.out.println("t2把锁1和锁2都获得了");
                }
            }
             ;
         });
         t1.start();
         t2.start();
    }
}
